import java.util.Scanner;

class Solution {

    /** 寻找数组的中心下标
     *  中心下标的左侧之和等于右侧之和
     *
     * @param nums
     * @return
     */
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];

        for (int i = 1; i < n; i++)
            f[i] = f[i-1] + nums[i - 1];

        for (int i = n - 2 ; i >= 0 ; i--)
            g[i] = g[i+1] + nums[i + 1];

        for (int i = 0; i < n; i++)
            if(f[i] == g[i])
                return i;

        return -1;

//        int n = nums.length;
//
//        int[] dp = new int[n + 1];
//        int count = 0;
//        for (int i = 1; i < n + 1; i++)
//            dp[i] = dp[i-1] + nums[i-1];
//
//        int i = 1;
//        for (; i <= n; i++) {
//            int f = dp[i-1],g = dp[n-1] - dp[i];
//            if(f == g)
//                count++;
//        }
//        if(count == 1) return i;
//        else if(count > 1) return -1;
//        else return 0;
    }


    /**
     * 二维前缀和
     */
    public static void twoDimensionalPrefix(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt(),q = sc.nextInt();
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 1; i < n + 1; i++)
            for (int j = 1; j < m + 1; j++)
                arr[i][j] = sc.nextInt();

        long[][] dp = new long[n + 1][m + 1];
        for (int i = 1; i < n + 1; i++)
            for (int j = 1; j < m + 1; j++)
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + arr[i][j];

        while (q > 0){
            int x1 = sc.nextInt(), y1 = sc.nextInt();
            int x2 = sc.nextInt(), y2 = sc.nextInt();
            System.out.println(dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1]);
            q--;
        }
    }

    /**
     * 一维前缀和
     */
    public void dimensionalPrefix(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),p = sc.nextInt();
        int[] nums = new int[n + 1];
        for (int i = 1; i < n + 1; i++)
            nums[i] = sc.nextInt();

        int[] dp = new int[n + 1];
        for (int i = 1; i < n + 1; i++)
            dp[i] = dp[i-1] + nums[i];

        while(p > 0){
            int l = sc.nextInt(), r = sc.nextInt();
            System.out.println(dp[r] - dp[l - 1]);
            p--;
        }
    }

}